{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "# -*- coding: utf-8 -*-\n",
    "\"\"\"\n",
    "Created on Wed Apr 18 17:43:00 2018\n",
    "\n",
    "@author: S103878\n",
    "\"\"\"\n",
    "\n",
    "import win32clipboard as wincb\n",
    "from pathlib import Path\n",
    "import time\n",
    "import xlwings as xw\n",
    "def filedo():\n",
    "    p = Path(r'D:\\视频')\n",
    "    title = '<table>\\n'\n",
    "    title_2 = '<td>file:///'\n",
    "    last_2 = '\" width=160 height=120 /></td></tr>\\n'\n",
    "    last = '</table>\\n'\n",
    "    l = [i for i in p.glob('**/*.MTS') if i.is_file()]\n",
    "    with open(r'd:\\视频.html', 'w') as f:\n",
    "        f.write(title)\n",
    "        for i in l:\n",
    "            f.write('<tr>\\n<td>'+str(i.parent)+'</td>\\n')\n",
    "            f.write('<td>'+i.name[:-4]+'</td>\\n')\n",
    "            f.write('<td>'+time.strftime('%Y-%m-%d', time.localtime(i.stat()[-1]))+'</td>\\n')\n",
    "            f.write(title_2+str(i)+'</td>\\n')\n",
    "        f.write(last)\n",
    "def write_file():\n",
    "    wb = xw.Book.caller()\n",
    "    wb.sheets[0].activate()\n",
    "    wb.sheets[0].range('a2').api.select\n",
    "    wb.sheets[0].api.paste\n",
    "    return 1\n",
    "\n",
    "def deal_Clipboard():\n",
    "    p = Path(r'd:\\视频.html')\n",
    "    wincb.OpenClipboard()\n",
    "    wincb.EmptyClipboard()\n",
    "    wincb.SetClipboardText(p.read_text())\n",
    "    wincb.CloseClipboard()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "filedo()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
